/**
 * 掉落盒子脚本，实现盒子碰撞及回收流程
 */
export default class Box extends Laya.Script {
    constructor() { super(); }

    onEnable(): void {
    }

    onUpdate(): void {
       
    }

    onTriggerEnter(other: any, self: any, contact: any): void {
        
    }

    /**使用对象池创建爆炸动画 */
    createEffect(): Laya.Animation {
        let ani: Laya.Animation = new Laya.Animation();
        ani.loadAnimation("test/TestAni.ani");
        ani.on(Laya.Event.COMPLETE, null, recover);
        function recover(): void {
            ani.removeSelf();
            Laya.Pool.recover("effect", ani);
        }
        return ani;
    }

    onDisable(): void {
        //盒子被移除时，回收盒子到对象池，方便下次复用，减少对象创建开销。
        Laya.Pool.recover("box1", this.owner);
    }
}